import axios from 'axios';
import settings from '@/config/settings';
import md5 from 'js-md5';
import {
	getTimeStamp
} from '@/utils/timestamp'
import { getToken, setToken } from '@/utils/localToken';
export default async () => {
	try {
		const timestamp = getTimeStamp()
		const sign = md5(settings.SecretKey + timestamp)
		const base_path=(import.meta.env.VITE_APP_APIHOST || '') as string
		let data= await axios.post(`${base_path}/adminuser/RefreshToken`, {
			timestamp: timestamp,
			sign: sign,
		}, {
			headers: {
				'Content-Type': 'application/json;charset=UTF-8',
				'Authorization': await getToken()
			}
		});
		const {
			code,result
		}=data.data;
		if(code==0){
			let token= result.token_type+' '+result.token
			setToken(token)
			return token;
		}else
		{
			setToken("")
			 location.href='#/user/login'
		}
		
	} catch (error) {
		console.log(error);
		setToken("")
		location.href='#/user/login'
	}
};
